﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods.Studio.Common.BaseClasses;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Prism.Events;
using Renci.iRods.Studio.Modules.Explorer.Events;

namespace Renci.iRods.Studio.Modules.Explorer.ViewModels
{
    public class PropertiesDockableViewModel : ViewModelBase
    {
        public object _selectedObject;

        public object SelectedObject
        {
            get
            {
                return this._selectedObject;
            }
            set
            {
                this._selectedObject = value;
                this.NotifyOfPropertyChange(() => this.SelectedObject);
            }
        }


        public PropertiesDockableViewModel()
        {
            var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            var selectedObjectChangedEvent = eventAggregator.GetEvent<SelectedObjectChangedEvent>();
            selectedObjectChangedEvent.Subscribe(OnSelectedObjectChanged);
        }

        private void OnSelectedObjectChanged(object selectedObject)
        {
            if (selectedObject != null)
            {
                this.SelectedObject = selectedObject;
            }
            else
            {
                this.SelectedObject = null;
            }
        }
    }
}
